package com.cao.meet.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.blankj.utilcode.util.EncryptUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.Utils;
import com.cao.meet.AsyncTaskActivity;
import com.cao.meet.OkAsyncActivity;
import com.cao.meet.PasswordView;
import com.cao.meet.R;
import com.cao.meet.alive.LiveService;
import com.cao.meet.swipelist.SwipeListActivity;
import com.cao.meet.vocie.VoiceActivity;

import study.nababy.recyclerview.first.demo_recyclerview.StaggeredGridLayoutActivity;
import study.nababy.recyclerview.first.normal.activity.GridRecycleActivity;
import study.nababy.recyclerview.first.normal.activity.PullRecycleActivity;
import study.nababy.recyclerview.first.recycler_banner.RecyclerBannerActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Intent mIntent;
    private StringBuffer passWord = new StringBuffer();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Utils.init(getApplication());
        initViews();
        EncryptUtils.encryptMD5ToString("");
        LiveService.toLiveService(this) ;
    }


    int count = 0;

    private void initViews() {
        final PasswordView pass_word = (PasswordView) findViewById(R.id.pass_word);
        final Button swipelist = (Button) findViewById(R.id.swipelist);
        swipelist.setOnClickListener(this);
        final Button list_recycle = (Button) findViewById(R.id.list_recycle);
        list_recycle.setOnClickListener(this);
        final Button grid_recycle = (Button) findViewById(R.id.grid_recycle);
        grid_recycle.setOnClickListener(this);
        final Button pull_recycle  = (Button) findViewById(R.id.pull_recycle);
        pull_recycle.setOnClickListener(this);
        final Button recycler_banner = (Button) findViewById(R.id.recycler_banner);
        recycler_banner.setOnClickListener(this);
        final Button text_image = (Button) findViewById(R.id.text_image);
        text_image.setOnClickListener(this);
        final Button pull_parse = (Button) findViewById(R.id.pull_parse);
        pull_parse.setOnClickListener(this);
        final Button login = (Button) findViewById(R.id.login);
        login.setOnClickListener(this);
        final Button change_voice = (Button) findViewById(R.id.change_voice);
        change_voice.setOnClickListener(this);
        final Button async_task = (Button) findViewById(R.id.async_task);
        async_task.setOnClickListener(this);
        final Button ok_async = (Button) findViewById(R.id.ok_async);
        ok_async.setOnClickListener(this);
        final  Button write_to_file = (Button) findViewById(R.id.write_to_file);
        write_to_file.setOnClickListener(this);
        pass_word.setMode(PasswordView.Mode.RECT);
        pass_word.setPasswordListener(new PasswordView.PasswordListener() {
            @Override
            public void passwordChange(String changeText) {
                    LogUtils.e(changeText);
                    if (passWord.length() != 6){
                        //拼接完整密码
                        passWord.append(changeText);
                    }else {
                        LogUtils.e(passWord.toString());
                    }
            }

            @Override
            public void passwordComplete() {
//                if (passWord.length() == 6){
//                    String pwd = passWord.toString();
//                    LogUtils.e(pwd);
//                }
//                if (passWord.length() == 5){
//                    if (count == 0){
//                        count ++;
//                        passwordComplete();
//                    }
//                }
//                pass_word.getMode().
            }

            @Override
            public void keyEnterPress(String password, boolean isComplete) {
//                if (isComplete){
                    LogUtils.e(password);
//                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //仿QQ侧滑删除
            case R.id.swipelist:
                mIntent = new Intent(getApplicationContext(), SwipeListActivity.class);
                startActivity(mIntent);
                break;
            //RecyclerView，打造ListView效果
            case R.id.list_recycle:
                mIntent = new Intent(getApplicationContext(), StaggeredGridLayoutActivity.class);
                startActivity(mIntent);
                break;
            //RecyclerView，打造GridView效果
            case R.id.grid_recycle:
                mIntent = new Intent(getApplicationContext(), GridRecycleActivity.class);
                startActivity(mIntent);
                break;
            //RecyclerView，打造瀑布流效果
            case R.id.pull_recycle:
                mIntent = new Intent(getApplicationContext(), PullRecycleActivity.class);
                startActivity(mIntent);
                break;
            case R.id.recycler_banner:
                mIntent = new Intent(getApplicationContext(), RecyclerBannerActivity.class);
                startActivity(mIntent);
                break;
            case R.id.text_image:
                mIntent = new Intent(getApplicationContext(),TextImageActivity.class);
                startActivity(mIntent);
                break;
            case R.id.pull_parse:
                mIntent = new Intent(getApplicationContext(),PullParseXMLActivity.class);
                startActivity(mIntent);
                break;
            case R.id.login:
                mIntent = new Intent(getApplicationContext(),LoginActivity.class);
                startActivity(mIntent);
                break;
            case R.id.change_voice:
                mIntent = new Intent(getApplicationContext(), VoiceActivity.class);
                startActivity(mIntent);
                break;
            case R.id.async_task:
                mIntent = new Intent(getApplicationContext(), AsyncTaskActivity.class);
                startActivity(mIntent);
                break;
            case R.id.ok_async:
                mIntent = new Intent(getApplicationContext(), OkAsyncActivity.class);
                startActivity(mIntent);
                break;
            case R.id.write_to_file:
                mIntent = new Intent(getApplicationContext(),WriteFileActivity.class);
                startActivity(mIntent);
                break;
        }
    }
}
